use umas0009_output, clear

sort zipcode
merge zipcode using "zcta_cbsa_rel_10.dta"
drop if _m<3
drop _m

gen zip=zipcode

sort zip
merge zip using zipcodelatlon
drop if _m==2
vincenty latitude longitude 42.09257 -72.616539, v(dist_wspringfield)
vincenty latitude longitude 42.099799 -72.585876, v(dist_springfield)
vincenty latitude longitude 42.17091 -72.332439, v(dist_palmer)
vincenty latitude longitude 42.154496 -71.487865, v(dist_milford)
vincenty latitude longitude 42.032528 -71.304016, v(dist_plainville)
vincenty latitude longitude 42.393798 -71.071973, v(dist_everett)
vincenty latitude longitude 42.2485 -71.8079, v(dist_worcester)
vincenty latitude longitude 42.393354 -71.000776, v(dist_boston)

gen closestB="West Springfield" if dist_wspringfield<dist_palmer & dist_wspringfield<dist_springfield
replace closestB="Springfield" if dist_springfield<dist_palmer & dist_springfield<dist_wspringfield
replace closestB="Palmer" if dist_palmer<dist_wspringfield & dist_palmer<dist_springfield

gen farthestB="West Springfield" if dist_wspringfield>dist_palmer & dist_wspringfield>dist_springfield
replace farthestB ="Springfield" if dist_springfield>dist_palmer & dist_springfield>dist_wspringfield
replace farthestB ="Palmer" if dist_palmer>dist_wspringfield & dist_palmer>dist_springfield

gen closestA="Milford" if dist_milford<dist_plainville & dist_milford<dist_everett & dist_milford<dist_worcester & dist_milford<dist_boston
replace closestA="Plainville" if dist_plainville<dist_milford  & dist_plainville<dist_everett & dist_plainville<dist_worcester & dist_plainville<dist_boston
replace closestA="Everett" if dist_everett<dist_milford  & dist_everett<dist_plainville & dist_everett<dist_worcester & dist_everett<dist_boston
replace closestA="Worcester" if dist_worcester<dist_milford  & dist_worcester<dist_plainville & dist_worcester<dist_everett & dist_worcester<dist_boston
replace closestA="Boston" if dist_boston<dist_milford  & dist_boston<dist_plainville & dist_boston<dist_everett & dist_boston<dist_worcester


gen region=1 if cbsa==14460
replace region=2 if cbsa==12700 | cbsa==39300
replace region=3 if cbsa==49340
replace region=4 if cbsa==38340 | cbsa==44140
label define region 1 "Boston Area" 2 "New Bedford/Cape Cod" 3 "Central MA" 4 "Western MA"
label values region region

gen region2=1 if region==1
replace region2=2 if region>1
label define region2 1 "Boston Area" 2 "Rest of MA"
label values region2 region2


gen incomecat=1 if faminc<=4
replace incomecat=2 if faminc>4 & faminc<10
replace incomecat=3 if faminc<97 & faminc>10

label define incomecat 1 "Less than $40k" 2 "$40k - $100k" 3 "Over $100k"
label values incomecat incomecat

gen ideo3=ideo5
recode ideo3 1/2=1 3=2 4/5=3 6=4
label define ideo3 1 "liberal" 2 "moderate" 3 "conservative"
label val ideo3 ideo3
label var ideo3 "Ideology 3 point"

recode pid3 4/5=3

gen age=2013-birthyr
gen agecat=1 if age<30
replace agecat=2 if age>29 & age<55
replace agecat=3 if age>54

label define agecat 1 "18-29" 2 "30-54" 3 "55+"
label values agecat agecat

recode q17_1-q18_9 (2=0)

recode q18_9 1=0 0=1, gen(gambler)

gen casino=q18_2

svyset [pw=weight]

ren q17_1 West_Springfield
ren q17_2 Springfield
ren q17_3 Palmer
ren q17_4 Worcester
ren q17_5 Milford
ren q17_6 Plainville
ren q17_7 Boston
ren q17_8 Everett
ren q17_9 Raynham

*** Support for Casinos
* Region A
tabstat Worcester-Everett [aw=weight], stat(mean n)

* Region B
tabstat West_Springfield-Palmer [aw=weight], stat(mean n)

* Region C 
tabstat Raynham [aw=weight], stat(mean n)

*restricted to those who made selection
generate select_a = Worcester+Milford+Plainville+Boston+Everett
generate select_b = West_Springfield+Springfield+Palmer
generate select_c = Raynham

* Region A
tabstat Worcester-Everett [aw=weight] if select_a==1, stat(mean n)

* Region B
tabstat West_Springfield-Palmer [aw=weight] if select_b==1, stat(mean n)

* Region C 
tabstat Raynham [aw=weight] if select_c, stat(mean n)


*********** Among those who have visited a casino

* Region A
tabstat Worcester-Everett [aw=weight], by(casino) stat(mean n)

* Region B
tabstat West_Springfield-Palmer [aw=weight], by(casino) stat(mean n)

**restricted to those who made selection
* Region A
tabstat Worcester-Everett [aw=weight] if select_a==1, by(casino) stat(mean n)

* Region B
tabstat West_Springfield-Palmer [aw=weight] if select_b==1, by(casino) stat(mean n)


************* Among those in the area

* Region A
tabstat Worcester-Everett [aw=weight] if region==1 | region==3, stat(mean n)

* Region B
tabstat West_Springfield-Palmer [aw=weight] if region==4, stat(mean n)

**restricted to those who made selection
* Region A
tabstat Worcester-Everett [aw=weight] if select_a==1 & region==1 | region==3, stat(mean n)

* Region B
tabstat West_Springfield-Palmer [aw=weight] if select_b==1 & region==4, stat(mean n)



************* Among those in the area, by whether do any gambling
* Region A
tabstat Worcester-Everett [aw=weight] if region==1 | region==3, by(gambler) stat(mean n)

* Region B
tabstat West_Springfield-Palmer [aw=weight] if region==4, by(gambler) stat(mean n)

**restricted to those who made selection
* Region A
tabstat Worcester-Everett [aw=weight] if select_a==1 & region==1 | region==3, by(gambler) stat(mean n)

* Region B
tabstat West_Springfield-Palmer [aw=weight] if select_b==1 & region==4, by(gambler) stat(mean n)


************* Among those in the area, by whether went to casino

* Region A
tabstat Worcester-Everett [aw=weight] if region==1 | region==3, by(casino) stat(mean n)

* Region B
tabstat West_Springfield-Palmer [aw=weight] if region==4, by(casino) stat(mean n)

**restricted to those who made selection
* Region A
tabstat Worcester-Everett [aw=weight] if select_a==1 & region==1 | region==3, by(casino) stat(mean n)

* Region B
tabstat West_Springfield-Palmer [aw=weight] if select_b==1 & region==4, by(casino) stat(mean n)


************ Support based on which Casino is closest

* Region A
tabstat Worcester-Everett [aw=weight]  if region==1 | region==3, by(closestA) stat(mean n)

* Region B
tabstat West_Springfield-Palmer [aw=weight] if region==4, by(closestB) stat(mean n)

**restricted to those who made selection


* Region A
tabstat Worcester-Everett [aw=weight]  if select_a==1 & region==1 | region==3, by(closestA) stat(mean n)

* Region B
tabstat West_Springfield-Palmer [aw=weight] if select_b==1 & region==4, by(closestB) stat(mean n)

